package edu.uts.reekie.designer.implementation.model;

import org.eclipse.swt.graphics.Image;

import edu.uts.reekie.designer.ImageHelper;
import edu.uts.reekie.designer.model.Multiple;
import edu.uts.reekie.designer.model.Nameable;
import edu.uts.reekie.designer.model.ViewNode;


public abstract class ViewComponent extends ViewNode implements Nameable{
	
	// properties
	public static String PROPERTY_NAME = "name";
	public static String PROPERTY_MULTIPLICITY = "multiplicity";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1;

	private static Image ICON = ImageHelper.createFromImplementationModelResource( "icons/plain16.gif");  //$NON-NLS-1$
	
	private static int count;
	
	public ViewComponent() {
		super();
		// set some default values
		setName("component " + getID()); 
	}
		

	
	private String name;
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#getName()
	 */
	public String getName(){
		return name;
	}
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#setName(java.lang.String)
	 */
	public void setName(String name){
		this.name = name;
		firePropertyChange(PROPERTY_NAME, null, name); //$NON-NLS-2$//$NON-NLS-1$
		
	}
	
	public Image getIconImage() {
		return ICON;
	}

	protected String getNewID() {
		return Integer.toString(count++);
	}

	public String toString() {
		return "Component \"" + name + "\""; 
	}

	private boolean isMultiple = false;
	
	public boolean isMultiple() {
		return isMultiple;
	}
	
	public void setMultiple(boolean isMul){
		if (this.isMultiple==isMul){
			return;
		}
		this.isMultiple = isMul;
		firePropertyChange(PROPERTY_MULTIPLICITY, new Boolean(!isMultiple), new Boolean(isMultiple)); //$NON-NLS-2$//$NON-NLS-1$
	}
	
	
}
